<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>老柳家：VLOOKUP功能网站</title>
    <style>
        body {
            margin: 20px;
            padding: 50px;
            background-color: #f5f7fa;

        }
        .container {
            max-width: 800px;
            margin: 0 auto;
            background: #fff;
            padding: 20px;
            border-radius: 40px;
            box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
        }
        h2 {
            text-align: center;
            color: #303133;
            margin-bottom: 20px;
        }
        .form-item {
            margin-bottom: 20px;
        }
        .form-item label {
            display: block;
            margin-bottom: 8px;
            color: #606266;
        }
        .form-item input, .form-item select {
            width: 100%;
            padding: 10px;
            border: 1px solid #dcdfe6;
            border-radius: 40px;
            box-sizing: border-box;
        }
        .form-item button {
            width: 100%;
            padding: 12px;
            background-color: white;
            border: 1px solid #dcdfe6;
            border-radius: 40px;
            color: #409EFF;
            text-align: center;
            font-size: 16px;
            cursor: pointer;
            transition: background-color 0.3s, border-color 0.3s;
        }
        .form-item button:hover {
            background-color: #ecf5ff;
            border-color: #409EFF;
        }
        .result {
            margin-top: 20px;
            padding: 20px;
            border: 2px solid #ebeef5;
            border-radius: 40px;
            background-color: #fff;
            width: 95%;
            opacity: 0;
            transform: translateY(20px);
            transition: opacity 0.5s, transform 0.5s;
        }
        .result.visible {
            opacity: 1;
            transform: translateY(0);
        }
        .result.success {
            border-left: 5px solid #67c23a;
        }
        .result.failure {
            border-left: 5px solid #f56c6c;
        }
    </style>
</head>
<body>
    <div class="container">
        <h2>老柳家：VLOOKUP功能网站</h2>
        <form id="uploadForm" enctype="multipart/form-data">
            <div class="form-item">
                <label for="file1">上传第一个Excel:</label>
                <input type="file" id="file1" name="file1" required><br><br>
            </div>
            <div class="form-item">
                <label for="file2">上传第二个Excel:</label>
                <input type="file" id="file2" name="file2" required><br><br>
            </div>
            <div class="form-item">
                <label for="keyColumn">输入参考列：如果A列为参考列，即输入 A :</label>
                <input type="text" id="keyColumn" name="keyColumn" required><br><br>
            </div>
            <div class="form-item">
                <button type="button" onclick="uploadFiles()">进行VLOOKUP合并Excel</button>
            </div>
        </form>
        <br>
        <a id="downloadLink" href="" download="result.xlsx" style="display:none;">Download Result</a>
        <script>
            async function uploadFiles() {
                const file1 = document.getElementById('file1').files[0];
                const file2 = document.getElementById('file2').files[0];
                const keyColumn = document.getElementById('keyColumn').value;
                const formData = new FormData();
                formData.append('file1', file1);
                formData.append('file2', file2);
                formData.append('keyColumn', keyColumn);
                const response = await fetch('/upload', { method: 'POST', body: formData });
                const result = await response.json();
                if (result.success) {
                    document.getElementById('downloadLink').href = result.url;
                    document.getElementById('downloadLink').style.display = 'block';
                } else {
                    alert('Error: ' + result.error);
                }
            }
        </script>
    </div>
</body>
</html>